package com.example.servicea.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.plugins.Page;
import com.example.servicea.dao.UserOrganizationMapper;
import com.example.servicea.entity.UserOrganizationEntity;
import com.example.servicea.service.UserOrganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * @Author generator.
 * @Date: 2017/10/26 10:58
 */
@Service("userOrganizationServiceImpl")
public class UserOrganizationServiceImpl implements UserOrganizationService {
	@Autowired
	private UserOrganizationMapper userOrganizationMapper;

    @Override
    public boolean insert(UserOrganizationEntity obj){
        return SqlHelper.retBool(userOrganizationMapper.insert(obj));
    }
    @Override
    public List<UserOrganizationEntity> selectList(UserOrganizationEntity userOrganization){
        EntityWrapper<UserOrganizationEntity> query = new EntityWrapper<UserOrganizationEntity>();
		return userOrganizationMapper.selectList(query);
	}

    @Override
    public Page selectPage(UserOrganizationEntity userOrganization, String page, String limit){
        EntityWrapper<UserOrganizationEntity> query = new EntityWrapper<UserOrganizationEntity>();
        List<UserOrganizationEntity> list = userOrganizationMapper.selectPage(
                new Page<UserOrganizationEntity>(Integer.parseInt(page),Integer.parseInt(limit)),
                query);
        int total = userOrganizationMapper.selectCount(query);
        Page UserOrganizationEntityPage = new Page();
        return UserOrganizationEntityPage;
	}
    @Override
    public int selectCount(UserOrganizationEntity userOrganization){
        EntityWrapper<UserOrganizationEntity> query = new EntityWrapper<UserOrganizationEntity>();
        return userOrganizationMapper.selectCount(query);
	}

    @Override
    public UserOrganizationEntity selectOne(UserOrganizationEntity userOrganization){
        return userOrganizationMapper.selectOne(new UserOrganizationEntity());
	}

    @Override
    public UserOrganizationEntity selectById(String id){
        return userOrganizationMapper.selectById(id);
	}

	@Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateById(UserOrganizationEntity userOrganization){
        return SqlHelper.retBool(userOrganizationMapper.updateById(userOrganization));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(String id){
        return SqlHelper.retBool(userOrganizationMapper.deleteById(Integer.parseInt(id)));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBatchIds(String ids){
        String[] s = ids.split(",");
        List<String> list = Arrays.asList(s);
        return SqlHelper.retBool(userOrganizationMapper.deleteBatchIds(list));
	}
	
}
